<template>
  <div>
    <el-table
        :data="tableData"
        style="width: 60%">
      <el-table-column
          prop="id"
          label="考试编号"
          width="120">
      </el-table-column>
      <el-table-column
          prop="name"
          label="考试名字"
          width="120">
      </el-table-column>
      <el-table-column
          prop="studentName"
          label="考试人"
          width="120">
      </el-table-column>
      <el-table-column
          label="考试时间"
          prop="testTime">
      </el-table-column>
<!--      <el-table-column label="是否开考">-->
<!--        <template slot-scope="scope">-->
<!--          <el-button v-if="scope.row.">-->

<!--          </el-button>-->
<!--        </template>-->
<!--      </el-table-column>-->
      <el-table-column label="操作">
        <template slot-scope="scope">



          <el-button v-if="scope.row.isExam == null"
              size="mini"
              @click="handleEdit(scope.$index, scope.row)">进行考试</el-button>
          <el-button v-if="scope.row.isExam == 1" type="success"
                     size="mini">已完成考试</el-button>

        </template>
      </el-table-column>
    </el-table>
    <el-pagination
        @size-change="handleSizeChange"
        v-bind:child-msg="pageparm"
        @current-change="handleCurrentChange"
        :current-page="pageparm.currentPage"
        :page-sizes="[3, 5, 10, 15]"
        :page-size="pageparm.pageSize"
        layout="total, sizes, prev, pager, next, jumper"
        :total="pageparm.total" style="margin-left:200px;margin-top:16px">
    </el-pagination>
  </div>
</template>

<script>
export default {
  name: "testList",
  created() {
    this.findTestList()
  },

  methods:{
    handleSizeChange(val) {
      console.log(`每页 ${val} 条`);
      this.formInline.limit =val
      this.formInline.page = 1
      //this.findAll(this.formInline)
      this.findTestList()
    },
    handleCurrentChange(val) {
      console.log(`当前页: ${val}`);
      this.formInline.page = val
      //this.findAll(this.formInline)
      this.findTestList()
    },
    findTestList(){

      this.$axios.post('http://localhost:8080/examAdministration/selectPage', this.formInline
      ).then(
          res=>{

            let data = res.data.data.list
            let information
            let tableData =[]
            for(let i in data){
              if(data[i].approvalTag ==1){
                information = JSON.parse(data[i].examInformation)

                    for (let j in information) {
                      console.log(information[j])
                      //判断id 现在写死的是id为一的登录

                      if (information[j].id == 1 && information[j].roleId == 2) {
                        tableData.push({
                          examId: data[i].id,
                          id: this.no,
                          testTime: data[i].examQuizTime,
                          studentName: information[j].username,
                          name: data[i].examName,
                          paperId: data[i].paperId,
                          isExam: data[i].isExam,
                          examTime: data[i].answerTime,


                        })
                        this.no++
              }}}}

            // for(let i of  data){
            //   console.log(i)
            //   if(i.approvalTag ==1) {
            //
            //
            //
            //     information = JSON.parse(i.examInformation)
            //     for (let j of information) {
            //
            //       //判断id 现在写死的是id为一的登录
            //
            //       if (j.id == 1 && j.roleId == 2) {
            //         tableData.push({
            //           examId: i.id,
            //           id: this.no,
            //           testTime: i.examQuizTime,
            //           studentName: j.username,
            //           name: i.examName,
            //           paperId: i.paperId,
            //           isExam: i.isExam,
            //           examTime: i.answerTime,
            //
            //
            //         })
            //
            //
            //         this.no++
            //       }
            //     }
            //   }
            // }
            this.tableData = tableData
            this.pageparm.currentPage = this.formInline.page
            this.pageparm.pageSize = this.formInline.limit
            this.pageparm.total = res.data.data.total

          }
      ).catch()
    },

    handleEdit(index, row) {

      this.$router.push({path:'/testPaper',
        query:{paperMessage:row.paperId,examId:row.examId,
          studentName:row.studentName,examTime:row.examTime}})
    },
  },
  data() {
    return {

      no:1,
      formInline:{
        page:1,
        limit:5
      },
      pageparm:{
        currentPage:1,
        pageSize:5,
        total:0,
      },
      tableData: [
       //   {
      //   id:1,
      //   name: "一年级数学期末考试",
      //   create_man: '王小虎',
      //   create_time: '2016-05-02'
      // },

        ]
    }
  }
}
</script>

<style scoped>

</style>